home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libimage / close.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.3 KB  |  91 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    iclose and iflush -
  19.  *
  20.  *                Paul Haeberli - 1984
  21.  *
  22.  */
  23. #include    <stdio.h>
  24. #include    <stdlib.h>
  25. #include    "image.h"
  26.  
  27. int
  28. iclose(image)
  29. register IMAGE     *image;
  30. {
  31.     long tablesize;
  32.  
  33.     iflush(image);
  34.     img_optseek(image, 0);
  35.     if (image->flags&_IOWRT) {
  36.     if(image->dorev)
  37.         cvtimage(image);
  38.     if (img_write(image,image,sizeof(IMAGE)) != sizeof(IMAGE)) {
  39.         i_errhdlr("iclose: error on write of image header\n");
  40.         return EOF;
  41.     }
  42.     if(image->dorev)
  43.         cvtimage(image);
  44.     if(ISRLE(image->type)) {
  45.         img_optseek(image, 512L);
  46.         tablesize = image->ysize*image->zsize*sizeof(long);
  47.         if(image->dorev)
  48.         cvtlongs(image->rowstart,tablesize);
  49.         if (img_write(image,image->rowstart,tablesize) != tablesize) {
  50.         i_errhdlr("iclose: error on write of rowstart\n");
  51.         return EOF;
  52.         }
  53.         if(image->dorev)
  54.         cvtlongs(image->rowsize,tablesize);
  55.         if (img_write(image,image->rowsize,tablesize) != tablesize) {
  56.         i_errhdlr("iclose: error on write of rowsize\n");
  57.         return EOF;
  58.         }
  59.     }
  60.     }
  61.     if(image->base) {
  62.     free(image->base);
  63.     image->base = 0;
  64.     }
  65.     if(image->tmpbuf) {
  66.     free(image->tmpbuf);
  67.     image->tmpbuf = 0;
  68.     }
  69.     if(ISRLE(image->type)) {
  70.     free(image->rowstart);
  71.     image->rowstart = 0;
  72.     free(image->rowsize);
  73.     image->rowsize = 0;
  74.     }
  75.     return(close(image->file));
  76. }
  77.  
  78. iflush(image)
  79. register IMAGE     *image;
  80. {
  81.     unsigned short *base;
  82.  
  83.     if ( (image->flags&_IOWRT)
  84.      && (base=image->base)!=NULL && (image->ptr-base)>0) {
  85.         if (putrow(image, base, image->y,image->z)!=image->xsize) {
  86.             image->flags |= _IOERR;
  87.             return(EOF);
  88.         }
  89.     }
  90. }
  91.